import os
from django.contrib.auth.models import User
from django.db import models
import datetime
# Create your models here.
from django.utils.datetime_safe import date


def get_hotel_path(instance, filename):
    return new_path(filename, path="images/hotel")


def get_company_path(instance, filename):
    return new_path(filename, path="images/company")


def new_path(filename, path):
    #you can change this path
    now_path = datetime.datetime.now().strftime("%d%m%Y%H%M%S")
    image_path = "{0}-{1}".format(now_path, filename)
    return os.path.join(path, image_path)


class Hotel(models.Model):
    name = models.CharField(max_length=200)
    address = models.CharField(max_length=255)
    website = models.URLField()
    desc = models.TextField()
    single = models.IntegerField()
    double = models.IntegerField()
    triple = models.IntegerField()
    image1 = models.ImageField(upload_to=get_hotel_path)
    image2 = models.ImageField(upload_to=get_hotel_path)
    image3 = models.ImageField(upload_to=get_hotel_path)
    longitude = models.FloatField()
    latitude = models.FloatField()

    def __unicode__(self):
        return self.name


class Review(models.Model):
    user = models.ForeignKey(User)
    hotel = models.ForeignKey(Hotel)
    comment = models.TextField()
    rating = models.IntegerField()

class Company(models.Model):
    companyName= models.CharField(max_length=50)
    companyImage = models.ImageField(upload_to=get_company_path)

    def __unicode__(self):
        return self.companyName


class Offer(models.Model):
    company = models.ForeignKey(Company)
    hotel = models.ForeignKey(Hotel)
    roomType = models.CharField(max_length=10)
    price = models.IntegerField()

class Book(models.Model):
    user = models.ForeignKey(User)
    offer = models.ForeignKey(Offer)
    mystart = models.DateTimeField()
    myend = models.DateTimeField()